<?php 
    $entity = pc_variable("entity");
    $type = pc_config("type." . pc_variable("typeName"));
    $attributeConfigurationManager = pc_config("cm.attributeConfigurationManager");
?>
<h2><?php pc_echo(pc_variable("title")); ?></h2>
<form action="./dispatcher.php" enctype="multipart/form-data" method="post">
    <fieldset>
        <input type="hidden" name="typeName" value="<?php pc_echo($type->getFullName()); ?>"/>
        <input type="hidden" name="id" value="<?php if($entity !== null) { pc_echo($entity->getId()); } ?>"/>
        <input type="hidden" name="targetPage.location" value="<?php pc_echo(pc_link("Query", array("typeName" => $type->getFullName()))); ?>"/>
        <?php 
            foreach($type->getAttributes() as $name => $attribute) {
                $attributeConfiguration = $attributeConfigurationManager->getAttributeConfiguration($attribute);
                if($attributeConfiguration === null || $attributeConfiguration->getEditView() !== null) {
                    pc_pagelet("show-entity/attribute/switch", 
                        array(
                            "entity" => $entity,
                            "attribute" => $attribute,
                            "name" => $name,
                            "value" => $entity !== null ? $entity->get($name) : null
                        ));
                }
            }
        ?>
    </fieldset>
    <fieldset class="buttons">
        <button class="save" type="submit" name="controller" value="Save"><?php pc_echo(pc_message("showEntity.save")); ?></button>
        <a href="<?php pc_echo(pc_link("Query", array("typeName" => $type->getFullName()))); ?>" class="cancel"/><?php pc_echo(pc_message("showEntity.cancel")); ?></a>
    </fieldset>
</form>
